/**
 * 清理localStorage中的错误数据
 * 在应用启动时自动执行
 */

export const cleanupStorage = () => {
  // 清理错误的userId值
  const userId = localStorage.getItem('userId');
  if (userId && 
      (userId === '[object Object]' || 
       userId === 'undefined' || 
       userId === 'null' ||
       userId.includes('object'))) {
    
    console.warn('🧹 [清理] 检测到无效的userId，自动清除:', userId);
    localStorage.removeItem('userId');
  }
  
  // 迁移旧的tempUserId到userId
  const tempUserId = localStorage.getItem('tempUserId');
  if (tempUserId && !userId) {
    if (tempUserId.length === 15 && /^\d{15}$/.test(tempUserId)) {
      console.log('🔄 [迁移] 将tempUserId迁移到userId:', tempUserId);
      localStorage.setItem('userId', tempUserId);
    }
    localStorage.removeItem('tempUserId');
  }
};

// 自动执行清理
if (typeof window !== 'undefined') {
  cleanupStorage();
}





